﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Panel.Master" Inherits="System.Web.Mvc.ViewPage<Prodma.DataAccess.Models.ViewModels.UserVm>" %>


<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
<%=System.Configuration.ConfigurationManager.AppSettings["pageTitle"] %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">



<form id="profil" method="post" action="/user/ChangeUserParameters/">
<div class="detailContainer">
    <div class="detailSection-50pc">
    <% SelectList productCategoryBrandList = (SelectList)ViewData["Marka"];%>
    <% SelectList kategoriList = (SelectList)ViewData["Kategori"]; %>
    <div class="detailSectionHeader">Ürün Gruplama Seçenekleri</div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Kategori :</div>
            <div class="detailSectionRowText-80pc">
                <%=Html.DropDownList("ddlKategori", kategoriList, "Kategori Seçiniz", new { @class = "listArchiveCombo" })%>
                <input type="hidden" value="0" name="Kategori" id="Kategori"/>
            </div>
        </div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Marka :</div>
            <div class="detailSectionRowText-80pc">
                <%=Html.DropDownList("ddlBrand", productCategoryBrandList, "Marka Seçiniz", new { @class = "listArchiveCombo" })%>
                <input type="hidden" value="0" name='Marka' id="Marka"/>
            </div>
        </div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Model :</div>
            <div class="detailSectionRowText-80pc">
               <select id="ddlModel" name="ddlModel" class="listArchiveCombo">
                                <option value="0">Model Seçiniz</option>
                            </select>
                            <input type="hidden" value="0" name='Model' id="Model" />
            </div>
        </div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc"></div>
            <div class="detailSectionRowText-80pc"><input type="button" id="btnSaveChanges" name="btnSaveChanges" onclick="submitForm();" value="Onayla" class="detailSectionControlButton" /></div>
        </div>
    </div>
    
    <input type="hidden" id="id" name="id" value='<%=ViewData.Model.ID %>' />
    <%if (ViewData["Filters"] != null)
      { %>
      <% Prodma.DataAccess.Database.tb_FilterParameters filters = (Prodma.DataAccess.Database.tb_FilterParameters)ViewData["Filters"]; %>
    <input type="hidden" id="savedBrand" name="savedBrand" value='<%= filters.MarkaID %>' />
    <input type="hidden" id="savedCategory" name="savedCategory" value='<%=filters.KategoriID %>' />
    <input type="hidden" id="savedModel" name="savedModel" value='<%=filters.ModelID %>' />
    
    <%} %>
</div>
</form>

<script type="text/javascript">

    window.onload = fda;
    function fda() {
        var marka = document.getElementById("ddlBrand");
        var kategori = document.getElementById("ddlKategori");
        //var marka = document.getElementById("ddlBrand");
        marka.value = document.getElementById("savedBrand").value;
        kategori.value = document.getElementById("savedCategory").value;

        if (document.getElementById("savedModel").value != null) {
            $.getJSON('/urunler/GetModels/?markaId=' + $('#ddlBrand :selected').val(), null, function (data) {

                $("#ddlModel").addItems(data);
                var model = document.getElementById("ddlModel");
                model.value = document.getElementById("savedModel").value;

            });

            

        }
    }
    
    function submitForm() {
        document.forms["profil"].submit();
    }

    $("#ddlBrand").change(function () {

        var marka = document.getElementById("ddlBrand");
        document.getElementById("Marka").value = marka.options[marka.selectedIndex].value;


        document.getElementById('ddlModel').options.length = 0;
        $("#ddlModel").append($('<option value="0">Model Seçiniz</option>'));


        var e = document.getElementById("ddlKategori");
        document.getElementById("Kategori").value = e.options[e.selectedIndex].value;

        var b = document.getElementById("ddlModel");
        document.getElementById("Model").value = b.options[b.selectedIndex].value;


        $.getJSON('/urunler/GetModels/?markaId=' + $('#ddlBrand :selected').val(), null, function (data) {

            $("#ddlModel").addItems(data);

        });
    });

    $.fn.addItems = function (data) {
        return this.each(function () {
            var list = this;
            $.each(data, function (index, itemData) {
                $("#ddlModel").append($('<option value=' + itemData.Value + '>' + itemData.Text + '</option>'));
            });
        });
    };


</script>

</asp:Content>
